
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;

import javax.swing.JOptionPane;

public class icsGenerator {


/***************************************************************************
  * 
 *****************************************************************************/
	//the start dt final format variable 
	static String dtstart = "";
	//the end dt final format variable
	static String dtend = "";
	//the variables for the year month day
	static int year = 2000;
	static int month = 01;
	static int day = 01;
	//the variables for the time of the event;
	static int time = 0100;
	//the class of the event
	static String theClass = "PRIVATE";
	//the description of the event
	static String description = "";
	//the location of said event
	static String location = "";
	//the name of the event
	static String summary = "";
	
	/**
	    *toString
	    * @param name is entered 
	    * @return the name entered 
	    */
	    public static void main (String[] args) {

	    }
	    public static void errorCheck(){
	    	//error check for the wrong day
	    	switch (month) {
	    		//checks to see if it is a month with 31 days
            	case 1: case 3: case 5:
            	case 7: case 8: case 10:
            	case 12:
            		//if the user input of days exceeds 31 it will mark it to 31
            		if(day > 31){
            			day = 31;
            		}
                break;
                //the next case will check for months with 30 days
            	case 4: case 6:
            	case 9: case 11:
            			//if the user input exceeds 30 days then it will correct it to 30 days
            		if (day > 30){
            			day = 30;
            		}
            	break;
                //for February it checks to see if it is a leap year or not by using a module 
            	case 2:
            		if (((year % 4 == 0) && !(year % 100 == 0)) || (year % 400 == 0)){
            			day = 29;	
            		}
            		else{
            			day = 28;
            		}
                break;
            default:
            	JOptionPane.showMessageDialog(null, "Please input a valid month");
                break;
	    	}
	    }
	    /**
		    *error checking for the user input for the Date fields of the program
		    * @param the date entered 
		    * @return the date given 
		    */
	    public static String format(){
	    	String date = year + month + day + "T" + time + "00Z";
	    	return date;
	    }
	    	
	    
	    
	    /**
		    *
		    *Finally entering it to the calendar 
		    */
	    public static void calendarInput(){
	    	 BufferedWriter outputStream;  
		        String content = "";

		        try{
		            outputStream = new BufferedWriter(new FileWriter(new File("test.ics")));
		           
		            content =
		                   "BEGIN:VCALENDAR\n" +
		                   "VERSION:2.0\n" +
		                   "X-WR-TIMEZONE:Pacific/Honolulu\n" + //will need to be change to the time zone specification required 'TZID'
		                   "BEGIN:VEVENT\n" +
		                   "DTSTART:" + dtstart + "\n" +
		                   "DTEND:" + dtend + "\n" +
		                   "CLASS:PRIVATE\n" +
		                   "DESCRIPTION: " + description + "\n" +
		                   "LOCATION:" + location + "\n" +
		                   "SUMMARY:"+ summary + "\n" +
		                   "END:VEVENT\n" +
		                   "END:VCALENDAR\n";
		           
		            outputStream.write(content);
		            outputStream.close();
		            
		        }
		        catch(IOException ie){
		           System.out.print("Unable to create file.");
		    	}
	    }
}
